Skip to content

DOC Update coding conventions#397

Merged
GuySartorelli merged 1 commit intosilverstripe:5from
creative-commoners:pulls/5/code-standards
Nov 26, 2023
Merged

DOC Update coding conventions#397
GuySartorelli merged 1 commit intosilverstripe:5from
creative-commoners:pulls/5/code-standards

Conversation

@emteknetnz
Copy link
Copy Markdown
Member

@emteknetnz emteknetnz commented Nov 6, 2023

Issue #323

Right now it requires some discussion with @silverstripe/core-team to see everyone's happy with the conventions that I've added in < This has been done

This PR will only focus on PHP. I've spun off a separate card for JS + SCSS

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
@michalkleiner
Copy link
Copy Markdown
Contributor

👍 Generally agree with all the proposed additions. It'd be great to have linter/phpcs/PhpStan rules for as many of these as possible.

Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some stuff here that seems like a duplication of the stuff below your additions - what's the intention there? Will you be removing all the old standards? Will you do a de-dupe separately? Or are the duplications not intended?

I'll hold off reviewing the existing standards until you've answered this.

I also assume that the other language coding standards have yet to be done.

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Copy link
Copy Markdown
Contributor

@ScopeyNZ ScopeyNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly feel strongly about trying to ratify member visibility, as some may remember from silverstripe/silverstripe-framework#8996.

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Copy link
Copy Markdown
Contributor

@maxime-rainville maxime-rainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of good stuff in there!!!

I would make the following assumptions explicit once and avoid repeating them over and over:

  • Best practices are approaches that will work well in most situations.
  • It's OK to occasionally ignore them. (Maybe we want to have two classes ... the ones that are nice to have but not so important ... and the ones that should only be ignored as a last results)
  • Best practices have not always been systematically applied, so you will encounter instances where they are not followed.

In term of language, I would be inclined to try to normalise it and avoid complicated dissertation. Maybe remove in-depth explanation of why we think something is a good.

I would focus on using the words "avoid" or "prefer" in most places. Maybe avoid using expression like "where possible" or "if practical".

Some extra questions we might want to address:

  • Do we prefer Promises or Async/Await in JS?
  • Prefer using the ORM instead of raw SQL.
  • Prefer DataObjectSchema::tableName() to get the table name for DataObject rather then hardcode the value.
  • Prefer generic/standard SQL syntax that work across all DataBase.

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
@ScopeyNZ
Copy link
Copy Markdown
Contributor

ScopeyNZ commented Nov 10, 2023

Do we prefer Promises or Async/Await in JS?

I'm against mentioning a preference here. They have different use-cases. Both are situational, and may even be used together, eg:

const thing = await fetch('url').then(response => response.json());

Prefer DataObjectSchema::tableName() to get the table name for DataObject rather then hardcode the value.

This should be a rule (at least it was when I was last peer-reviewing 😅 )

@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch 2 times, most recently from 205bb53 to 40b1e83 Compare November 13, 2023 03:33
@emteknetnz emteknetnz marked this pull request as ready for review November 13, 2023 03:34
@emteknetnz
Copy link
Copy Markdown
Member Author

emteknetnz commented Nov 13, 2023

Have made recommended edits. Have also updated the content that was previously on the page and either made it much more concise or removed. Ready for review again

@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch from 40b1e83 to 33d0d14 Compare November 13, 2023 03:49
Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxime-rainville in #397 (review) you said

Maybe avoid using expression like "where possible" or "if practical".

There's still some of that in here so you may want to look and see if you're okay with the way that language has been used in the new revision.

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch from 33d0d14 to cb1c594 Compare November 14, 2023 00:26
Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not done:

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch 2 times, most recently from b7d6716 to d5fb128 Compare November 14, 2023 02:31
@GuySartorelli
Copy link
Copy Markdown
Member

@maxime-rainville here are the specific things you need to double check:

@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch from d5fb128 to 31a6d56 Compare November 14, 2023 03:55
Copy link
Copy Markdown
Contributor

@maxime-rainville maxime-rainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe avoid using expression like "where possible" or "if practical".

There's still some of that in here so you may want to look and see if you're okay with the way that language has been used in the new revision.

I had a glance and didn't see anything obviously standing out. By general point was that "where possible" or "if practical" is kind of implied when drafting best practices.

Comment thread en/05_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md Outdated
@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch from 31a6d56 to 2dcd339 Compare November 26, 2023 21:17
Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No outstanding requested changes.

@GuySartorelli GuySartorelli merged commit a80f184 into silverstripe:5 Nov 26, 2023
@GuySartorelli GuySartorelli deleted the pulls/5/code-standards branch November 26, 2023 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants